package com.jziver.library.controller;

import com.jziver.library.entiry.BookInfo;
import com.jziver.library.service.BookInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * Created by csxhu on 2016/7/5.
 */
@Controller
public class BookInfoController {

    private BookInfoService bookInfoService;

    @Autowired
    public BookInfoController(BookInfoService bookInfoService) {
        this.bookInfoService = bookInfoService;
    }

    @RequestMapping("/")
    public String findAll(Model model) {
        model.addAttribute("books", bookInfoService.findAll());
        return "books";
    }

    @ResponseBody
    @RequestMapping("/bookinfo/{id}")
    public BookInfo findOne(@PathVariable("id") Integer id) {
        return bookInfoService.findOne(id);
    }

}
